<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>File Source for outputfilter.trimwhitespace.php</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
		</head>
		<body>
						<h1>Source for file outputfilter.trimwhitespace.php</h1>
<p>Documentation is available at <a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html">outputfilter.trimwhitespace.php</a></p>
<div class="src-code">
<div class="src-code"><ol><li><div class="src-line"><a name="a1"></a><span class="src-php">&lt;?php</span></div></li>
<li><div class="src-line"><a name="a2"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a3"></a><span class="src-doc">&nbsp;*&nbsp;Smarty&nbsp;plugin</span></div></li>
<li><div class="src-line"><a name="a4"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@package</span><span class="src-doc">&nbsp;Templates</span></div></li>
<li><div class="src-line"><a name="a5"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@subpackage</span><span class="src-doc">&nbsp;Smarty_plugins</span></div></li>
<li><div class="src-line"><a name="a6"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a7"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a8"></a><span class="src-doc">/**</span></div></li>
<li><div class="src-line"><a name="a9"></a><span class="src-doc">&nbsp;*&nbsp;Smarty&nbsp;trimwhitespace&nbsp;outputfilter&nbsp;plugin</span></div></li>
<li><div class="src-line"><a name="a10"></a><span class="src-doc">&nbsp;*</span></div></li>
<li><div class="src-line"><a name="a11"></a><span class="src-doc">&nbsp;*&nbsp;File:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outputfilter.trimwhitespace.php&lt;br&gt;</span></div></li>
<li><div class="src-line"><a name="a12"></a><span class="src-doc">&nbsp;*&nbsp;Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;outputfilter&lt;br&gt;</span></div></li>
<li><div class="src-line"><a name="a13"></a><span class="src-doc">&nbsp;*&nbsp;Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;trimwhitespace&lt;br&gt;</span></div></li>
<li><div class="src-line"><a name="a14"></a><span class="src-doc">&nbsp;*&nbsp;Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Jan&nbsp;25,&nbsp;2003&lt;br&gt;</span></div></li>
<li><div class="src-line"><a name="a15"></a><span class="src-doc">&nbsp;*&nbsp;Purpose:&nbsp;&nbsp;trim&nbsp;leading&nbsp;white&nbsp;space&nbsp;and&nbsp;blank&nbsp;lines&nbsp;from</span></div></li>
<li><div class="src-line"><a name="a16"></a><span class="src-doc">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;template&nbsp;source&nbsp;after&nbsp;it&nbsp;gets&nbsp;interpreted,&nbsp;cleaning</span></div></li>
<li><div class="src-line"><a name="a17"></a><span class="src-doc">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;up&nbsp;code&nbsp;and&nbsp;saving&nbsp;bandwidth.&nbsp;Does&nbsp;not&nbsp;affect</span></div></li>
<li><div class="src-line"><a name="a18"></a><span class="src-doc">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;&lt;PRE&gt;&gt;&lt;/PRE&gt;&nbsp;and&nbsp;&lt;SCRIPT&gt;&lt;/SCRIPT&gt;&nbsp;blocks.&lt;br&gt;</span></div></li>
<li><div class="src-line"><a name="a19"></a><span class="src-doc">&nbsp;*&nbsp;Install:&nbsp;&nbsp;Drop&nbsp;into&nbsp;the&nbsp;plugin&nbsp;directory,&nbsp;call</span></div></li>
<li><div class="src-line"><a name="a20"></a><span class="src-doc">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;code&gt;$smarty-&gt;load_filter('output','trimwhitespace');&lt;/code&gt;</span></div></li>
<li><div class="src-line"><a name="a21"></a><span class="src-doc">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from&nbsp;application.</span></div></li>
<li><div class="src-line"><a name="a22"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@author</span><span class="src-doc">&nbsp;&nbsp;&nbsp;Monte&nbsp;Ohrt&nbsp;&lt;monte&nbsp;at&nbsp;ohrt&nbsp;dot&nbsp;com&gt;</span></div></li>
<li><div class="src-line"><a name="a23"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@author</span><span class="src-doc">&nbsp;Contributions&nbsp;from&nbsp;Lars&nbsp;Noschinski&nbsp;&lt;lars@usenet.noschinski.de&gt;</span></div></li>
<li><div class="src-line"><a name="a24"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@version</span><span class="src-doc">&nbsp;&nbsp;1.3</span></div></li>
<li><div class="src-line"><a name="a25"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">string&nbsp;</span></div></li>
<li><div class="src-line"><a name="a26"></a><span class="src-doc">&nbsp;*&nbsp;</span><span class="src-doc-coretag">@param&nbsp;</span><span class="src-doc-type">Smarty&nbsp;</span></div></li>
<li><div class="src-line"><a name="a27"></a><span class="src-doc">&nbsp;*/</span></div></li>
<li><div class="src-line"><a name="a28"></a><span class="src-key">function&nbsp;</span><a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html#functionsmarty_outputfilter_trimwhitespace">smarty_outputfilter_trimwhitespace</a><span class="src-sym">(</span><span class="src-var">$source</span><span class="src-sym">,&nbsp;</span><span class="src-sym">&amp;</span><span class="src-var">$smarty</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a29"></a><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a30"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Pull&nbsp;out&nbsp;the&nbsp;script&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a31"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/preg_match_all">preg_match_all</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;!is&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">,&nbsp;</span><span class="src-var">$match</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a32"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$_script_blocks&nbsp;</span>=&nbsp;<span class="src-var">$match</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a33"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$source&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;script[^&gt;]*?&gt;.*?&lt;/script&gt;!is&quot;</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a34"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'@@@SMARTY:TRIM:SCRIPT@@@'</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a35"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a36"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Pull&nbsp;out&nbsp;the&nbsp;pre&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a37"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/preg_match_all">preg_match_all</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;pre[^&gt;]*?&gt;.*?&lt;/pre&gt;!is&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">,&nbsp;</span><span class="src-var">$match</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a38"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$_pre_blocks&nbsp;</span>=&nbsp;<span class="src-var">$match</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a39"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$source&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;pre[^&gt;]*?&gt;.*?&lt;/pre&gt;!is&quot;</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a40"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'@@@SMARTY:TRIM:PRE@@@'</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a41"></a>&nbsp;&nbsp;&nbsp;&nbsp;</div></li>
<li><div class="src-line"><a name="a42"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;Pull&nbsp;out&nbsp;the&nbsp;textarea&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a43"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.php.net/preg_match_all">preg_match_all</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;textarea[^&gt;]*?&gt;.*?&lt;/textarea&gt;!is&quot;</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">,&nbsp;</span><span class="src-var">$match</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a44"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$_textarea_blocks&nbsp;</span>=&nbsp;<span class="src-var">$match</span><span class="src-sym">[</span><span class="src-num">0</span><span class="src-sym">]</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a45"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$source&nbsp;</span>=&nbsp;<a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">&quot;!&lt;textarea[^&gt;]*?&gt;.*?&lt;/textarea&gt;!is&quot;</span><span class="src-sym">,</span></div></li>
<li><div class="src-line"><a name="a46"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-str">'@@@SMARTY:TRIM:TEXTAREA@@@'</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a47"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a48"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;remove&nbsp;all&nbsp;leading&nbsp;spaces,&nbsp;tabs&nbsp;and&nbsp;carriage&nbsp;returns&nbsp;NOT</span></div></li>
<li><div class="src-line"><a name="a49"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;preceeded&nbsp;by&nbsp;a&nbsp;php&nbsp;close&nbsp;tag.</span></div></li>
<li><div class="src-line"><a name="a50"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$source&nbsp;</span>=&nbsp;<a href="http://www.php.net/trim">trim</a><span class="src-sym">(</span><a href="http://www.php.net/preg_replace">preg_replace</a><span class="src-sym">(</span><span class="src-str">'/((?&lt;!\?&gt;)\n)[\s]+/m'</span><span class="src-sym">,&nbsp;</span><span class="src-str">'\1'</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">))</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a51"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a52"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;replace&nbsp;textarea&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a53"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html#functionsmarty_outputfilter_trimwhitespace_replace">smarty_outputfilter_trimwhitespace_replace</a><span class="src-sym">(</span><span class="src-str">&quot;@@@SMARTY:TRIM:TEXTAREA@@@&quot;</span><span class="src-sym">,</span><span class="src-var">$_textarea_blocks</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a54"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a55"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;replace&nbsp;pre&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a56"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html#functionsmarty_outputfilter_trimwhitespace_replace">smarty_outputfilter_trimwhitespace_replace</a><span class="src-sym">(</span><span class="src-str">&quot;@@@SMARTY:TRIM:PRE@@@&quot;</span><span class="src-sym">,</span><span class="src-var">$_pre_blocks</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a57"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a58"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-comm">//&nbsp;replace&nbsp;script&nbsp;blocks</span></div></li>
<li><div class="src-line"><a name="a59"></a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html#functionsmarty_outputfilter_trimwhitespace_replace">smarty_outputfilter_trimwhitespace_replace</a><span class="src-sym">(</span><span class="src-str">&quot;@@@SMARTY:TRIM:SCRIPT@@@&quot;</span><span class="src-sym">,</span><span class="src-var">$_script_blocks</span><span class="src-sym">,&nbsp;</span><span class="src-var">$source</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a60"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a61"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">return&nbsp;</span><span class="src-var">$source</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a62"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a63"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a64"></a><span class="src-key">function&nbsp;</span><a href="../Templates/Smarty_plugins/_library---templates---smarty---plugins---outputfilter.trimwhitespace.php.html#functionsmarty_outputfilter_trimwhitespace_replace">smarty_outputfilter_trimwhitespace_replace</a><span class="src-sym">(</span><span class="src-var">$search_str</span><span class="src-sym">,&nbsp;</span><span class="src-var">$replace</span><span class="src-sym">,&nbsp;</span><span class="src-sym">&amp;</span><span class="src-var">$subject</span><span class="src-sym">)&nbsp;</span><span class="src-sym">{</span></div></li>
<li><div class="src-line"><a name="a65"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$_len&nbsp;</span>=&nbsp;<a href="http://www.php.net/strlen">strlen</a><span class="src-sym">(</span><span class="src-var">$search_str</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a66"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$_pos&nbsp;</span>=&nbsp;<span class="src-num">0</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a67"></a>&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">for&nbsp;</span><span class="src-sym">(</span><span class="src-var">$_i</span>=<span class="src-num">0</span><span class="src-sym">,&nbsp;</span><span class="src-var">$_count</span>=<a href="http://www.php.net/count">count</a><span class="src-sym">(</span><span class="src-var">$replace</span><span class="src-sym">)</span><span class="src-sym">;&nbsp;</span><span class="src-var">$_i</span>&lt;<span class="src-var">$_count</span><span class="src-sym">;&nbsp;</span><span class="src-var">$_i</span>++<span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a68"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">if&nbsp;</span><span class="src-sym">((</span><span class="src-var">$_pos</span>=<a href="http://www.php.net/strpos">strpos</a><span class="src-sym">(</span><span class="src-var">$subject</span><span class="src-sym">,&nbsp;</span><span class="src-var">$search_str</span><span class="src-sym">,&nbsp;</span><span class="src-var">$_pos</span><span class="src-sym">))</span>!==<span class="src-id">false</span><span class="src-sym">)</span></div></li>
<li><div class="src-line"><a name="a69"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-var">$subject&nbsp;</span>=&nbsp;<a href="http://www.php.net/substr_replace">substr_replace</a><span class="src-sym">(</span><span class="src-var">$subject</span><span class="src-sym">,&nbsp;</span><span class="src-var">$replace</span><span class="src-sym">[</span><span class="src-var">$_i</span><span class="src-sym">]</span><span class="src-sym">,&nbsp;</span><span class="src-var">$_pos</span><span class="src-sym">,&nbsp;</span><span class="src-var">$_len</span><span class="src-sym">)</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a70"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">else</span></div></li>
<li><div class="src-line"><a name="a71"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span class="src-key">break</span><span class="src-sym">;</span></div></li>
<li><div class="src-line"><a name="a72"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a73"></a><span class="src-sym">}</span></div></li>
<li><div class="src-line"><a name="a74"></a>&nbsp;</div></li>
<li><div class="src-line"><a name="a75"></a><span class="src-php">?&gt;</span></div></li>
</ol></div>
</div>
	<p class="notes" id="credit">
		Documentation generated on Tue, 02 Mar 2010 07:47:13 +0000 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.4.1</a>
	</p>
	</body>
</html>